package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.PlaneType;
import com.ktgj.flight.service.IPlaneTypeService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机型信息维护Controller
 * 
 * @author ruoyi
 * @date 2021-08-30
 */
@ControllerAdvice
@RestController
@RequestMapping("/type")
public class PlaneTypeController extends BaseController
{
    @Autowired
    private IPlaneTypeService planeTypeService;

    /**
     * 查询机型信息维护列表
     */
    //@PreAuthorize(hasPermi = "flight:type:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody PlaneType planeType)
    {
        startPage();
        List<PlaneType> list = planeTypeService.selectPlaneTypeList(planeType);
        return getDataTable(list);
    }

    /**
     * 导出机型信息维护列表
     */
    //@PreAuthorize(hasPermi = "flight:type:export")
    @Log(title = "机型信息维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlaneType planeType) throws IOException
    {
        List<PlaneType> list = planeTypeService.selectPlaneTypeList(planeType);
        ExcelUtil<PlaneType> util = new ExcelUtil<PlaneType>(PlaneType.class);
        util.exportExcel(response, list, "机型信息维护数据");
    }

    /**
     * 获取机型信息维护详细信息
     */
    //@PreAuthorize(hasPermi = "flight:type:query")
    @PostMapping("/getInfo")
    public AjaxResult getInfo(@RequestBody Map<String, Object> map)
    {
        Long id = Long.valueOf(map.get("id").toString());
        return AjaxResult.success(planeTypeService.selectPlaneTypeById(id));
    }

    /**
     * 新增机型信息维护
     */
    //@PreAuthorize(hasPermi = "flight:type:add")
    @Log(title = "机型信息维护", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody PlaneType planeType)
    {
        return toAjax(planeTypeService.insertPlaneType(planeType));
    }

    /**
     * 修改机型信息维护
     */
    //@PreAuthorize(hasPermi = "flight:type:edit")
    @Log(title = "机型信息维护", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody PlaneType planeType)
    {
        return toAjax(planeTypeService.updatePlaneType(planeType));
    }

    /**
     * 删除机型信息维护
     */
    //@PreAuthorize(hasPermi = "flight:type:remove")
    @Log(title = "机型信息维护", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public AjaxResult remove(@RequestBody Map<String, Object> map)
    {
        Long id = Long.valueOf(map.get("id").toString());
        return toAjax(planeTypeService.deletePlaneTypeById(id));
    }
}
